package com.hg.helix.laboratory.demo.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hg.helix.laboratory.demo.core.Result;
import com.hg.helix.laboratory.demo.entity.HgDemoUserInfoEntity;
import com.hg.helix.laboratory.demo.service.HgDemoUserInfoService;

/**
 * 
 * @author zhaowei
 *
 */

@RestController
@RequestMapping(value = "/hgDemoUserInfo")
public class HgDemoUserInfoController {

	@Autowired
    private HgDemoUserInfoService hgDemoUserInfoService;
	
	/**
	 * 新增用户信息
	 * @param hgDemoUserInfo
	 * @return
	 */
	@PostMapping(value = "")
	public Result<?> add(@RequestBody HgDemoUserInfoEntity hgDemoUserInfo) {
		Boolean b = hgDemoUserInfoService.add(hgDemoUserInfo);
		if(b) {
			return Result.success("添加成功"); 
		}else {
			return Result.success("添加失败"); 
		}
		
	}
	
	/**
	 * 删除用户信息
	 *
	 * @param spaMenu
	 * @return
	 */
	@DeleteMapping(value = "")
	public Result<?> del(@RequestParam(name="id",required=true) Long id) {
		Boolean b = hgDemoUserInfoService.del(id);
		if(b) {
			return Result.success("删除成功"); 
		}else {
			return Result.success("删除失败"); 
		}
		
	}
	
	/**
	 * 修改用户信息
	 *
	 * @param spaMenu
	 * @return
	 */
	@PutMapping(value = "")
	public Result<?> update(@RequestBody HgDemoUserInfoEntity hgDemoUserInfo) {
		Boolean b = hgDemoUserInfoService.update(hgDemoUserInfo);
		if(b) {
			return Result.success("修改成功"); 
		}else {
			return Result.success("修改失败"); 
		}
		
	}
	
	/**
	 * 获取全部数据
	 * @return
	 */
	@GetMapping(value = "")
	public Result<?> getAll() {
		List<HgDemoUserInfoEntity> list = hgDemoUserInfoService.getAll();
		return Result.success("查询成功", list); 
		
	}
	
	/**
	 * 获取全部数据
	 * @return
	 */
	@GetMapping(value = "")
	public Result<?> getById(@RequestParam(name="id",required=true) Long id) {
		HgDemoUserInfoEntity hgDemoUserInfo = hgDemoUserInfoService.getById(id);
		return Result.success("查询成功", hgDemoUserInfo); 
		
	}
}
